var cow_skin_type = cc.Class({
    name: 'cow_skin_type',
    properties: {
        cow_status: {
            type: cc.SpriteFrame,
            default: []
        }
    }
})
cc.Class({
    extends: cc.Component,
    properties: {
        cow_skin: {
            type: cow_skin_type,
            default: []
        }
    },
    onLoad () {
        // 1. 随机生成牛
        var cow_type = Math.random()*3 // [0, 3)
        this.cow_type = Math.floor(cow_type) // 取整
        if (this.cow_type >= 3) {
            this.cow_type = 0
        }
        // 2. 帧动画
        // 2.1 添加帧动画组件
        this.anim_com = this.node.addComponent('frame_anim')
        // 2.2 播放
        this.cowWalk()
        // 2.3 移动速度
        this.speed_x = Math.random() * 200 + 200
    },
    cowWalk () {
        this.anim_com.sprite_frames = this.cow_skin[this.cow_type].cow_status
        this.anim_com.duration = 0.5
        this.anim_com.play_loop()
    },
    update (dt) {
        var move_x = -(this.speed_x * dt)
        this.node.x += move_x
        if (this.node.x < -500) {   // 超出屏幕
            // 移除组件
            this.node.removeFromParent()
        }
    },
    start () {

    }
});
